﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Share/Index.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<head>
<base target="_self">
</head>
<div style="margin-top:20px;">
            <table style="width:100%;border:1px;border-color:White;text-align:left;" cellpadding="0" cellspacing="0">
            <tr><td style="border:1px;border-color:White;">ISBN:<input type="text" id="isbn" /><input type="button" id="btnaddisbn" value="新增" /></td></tr>
            <tr><td style="border:1px;border-color:White;">批量上传：<% Html.RenderPartial("~/Views/Plugins/jqueryUploadFile.ascx", (ViewData["uploadFileId"] = "isbns"));%><input type="button" id="btnadd" value="批量上传" />批量上传内容存放在txt格式文件中，文件内容中isbn编号之间用'换行符'分隔</td></tr>
            </table>
</div>
  <table id="tableExcel" cellspacing="0" style="width:100%;">
  <caption style="text-align:left;margin-left:50px;font-family:@宋体;font-weight:bold;">图书名：
 <%=Server.HtmlDecode(Request["bookname"].ToString())%>
 </caption>
             <tr>
             <th>ISBN</th>
              <th>单本书(ISBN)状态</th>
             <th>最后操作人</th>
             <th>操作时间</th>
             <th></th>
             </tr>
             <tbody id="usercardlist">
             
             <% 
                 string id = Request["lbid"];
                 BIZ.BookOper bo = new BIZ.BookOper();
                 IList li = bo.getbookIsbnList(id);
                 foreach (Hashtable tb in li)
                 {
              %>
                <tr>
                <td><%=tb["lbd_isbn"]%></td>
                <td><%=Enum.GetName(typeof(DAL.Enums.isbnstate), int.Parse(tb["lbd_state"].ToString()))%></td>
                <td><%=tb["adminname"]%></td>
                <td><%=tb["lasttime"]%></td>
                <td>
                <% 
                     if (int.Parse(tb["lbd_state"].ToString()) != ((int)DAL.Enums.isbnstate.图书丢失))
                     {
                %>
                <a href="javascript:void(0);" onclick="changestate('<%=tb["lbd_id"] %>');">标记为丢失</a>
                <% 
                     }    
                %>
                </td>
                </tr>
              <%   
                 }
              %>
             </tbody>
             </table>
             <script language="javascript" type="text/javascript">
             $.ajaxSetup({ 
                async: false 
              }); 
                function changestate(id) {
                    if (confirm("确定要修改图书状态?")) {
                        $.post("/LibraryBook/changeisbnstate.html?" + (new Date()).getTime(), { res: id }, function (dta) {
                            alert("该ISBN的图书成功标记为丢失");
                            booksCountJs('<%=id %>');
                            window.returnValue=1; 
                            window.close();
                        });
                    }
                }
                function booksCountJs(lbid){
                        $.post("/LibraryBook/booksCountJs.html?" + (new Date()).getTime(), { lbid:lbid }, function (dta) {
 
                         });
                }
                 $(function () {
                     function addisbn(isbn) {
                         $.post("/LibraryBook/saveisbn.html?" + (new Date()).getTime(), { res: <%=id %>,isbn:isbn }, function (dta) {
                             if(dta==0){
                                alert("isbn:"+isbn+",已经存在，添加失败");
                             }
                             else if(dta==1){
                                alert("isbn:"+isbn+",添加成功");
                             }
                             else{
                                alert("isbn:"+isbn+",添加失败");
                             }
                         });
                     }
                     $("#btnaddisbn").click(function () {
                         var isbn = $.trim($("#isbn").val());
                         if(isbn==""){
                            alert("isbn不能为空");
                            return false;
                         }
                         if (confirm("确定添加?")) {
                            addisbn(isbn);
                            booksCountJs('<%=id %>');
                            window.returnValue=1; 
                            window.close();
                         }
                     });
                     $("#btnadd").click(function(){
                         var path = $('#isbns').attr('filepath');
                         if(path==undefined){
                            alert("请选择批量导入文件（注：文件内容中isbn编号之间用'换行符'分隔）");
                            return false;
                         }
                         $.post("/LibraryBook/getTxtisbn.html?" + (new Date()).getTime(), { path: path }, function (dta) {
                                  if (confirm("确定要批量添加isbn?")) {
                                    var reg = new RegExp('"',"g");
                                    var isbns=[];
                                    isbns=dta.replace(reg, "").split(',');
                                    for(var i=0;i<isbns.length;i++){
                                        if($.trim(isbns[i])!="")
                                            addisbn(isbns[i]);
                                    }
                                    booksCountJs('<%=id %>');
                                    window.returnValue=1; 
                                    window.close();
                                  }
                         });
                     });
                 });
             </script>

</asp:Content>
